package sanmubird.club.mock.controller;

/*
 * @author sam
 * @date 2019/12/6 10:37
 * @description 功能描述
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sanmubird.club.mock.dao.beans.UserDTO;
import sanmubird.club.mock.service.UserService;
import sanmubird.club.mock.sqlrunner.SqlRunnerService;

import java.util.List;
import java.util.Map;


/**
 * @author Sam
 */
@RestController
@RequestMapping("/mock")
public class SimpleMockControllerDemo {

	@Autowired
	private UserService userService;

	@Autowired
	private SqlRunnerService sqlRunnerService;

	@GetMapping("/simpleGetDemo")
	public String simpleGetDemo(@RequestParam String name) {
		return "hello " + name;
	}

	@GetMapping("/simplePathVariableGetDemo/{action}")
	public String simplePathVariableGetDemo(@RequestParam String name, @PathVariable String action) {
		return action + " " + name;
	}

	@PostMapping("/simpleJsonPostDemo")
	public String simpleJsonPostDemo(@RequestBody String jsonStr) {
		return jsonStr;
	}

	@PostMapping("/simpleFileUploadDemo")
	public String simpleFileUploadDemo(MultipartFile file, @RequestParam(name = "fileType") String fileType) {
		System.out.println("fileType" + fileType);
		System.out.println("请求已到达");
		return file.getOriginalFilename();
	}

	@GetMapping("/user")
	public String getUserList() {
		UserDTO userDTO = new UserDTO();
		userDTO.setName("zs");
		List<UserDTO> list = userService.selectList(userDTO);
		return list.toString();
	}

	@GetMapping("/userList")
	public String getUserList2() {
		List<Map<String, Object>> maps = sqlRunnerService.selectList("select * from USER ");
		return maps.toString();
	}

}
